package com.example.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.domain.User;
import com.example.mapper.VolunteerDao;
import com.example.domain.Volunteer;
import com.example.service.IVolunteerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VolunteerImpl extends ServiceImpl<VolunteerDao, Volunteer> implements IVolunteerService {

    @Autowired
    private VolunteerDao volunteerDao;

//    根据条件查询用户信息
    @Override
    public Volunteer getOne(String name, String phone) {
        LambdaQueryWrapper<Volunteer> lwq = new LambdaQueryWrapper<>();
        lwq.eq(Volunteer::getName,name).eq(Volunteer::getPhone,phone);
        Volunteer volunteer = volunteerDao.selectOne(lwq);
        return volunteer;
    }
//  添加用户时的查询条件
    @Override
    public Volunteer getVolunteer(String name) {
        LambdaQueryWrapper<Volunteer> lwq = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<Volunteer> eq = lwq.eq(Volunteer::getName, name);
        Volunteer volunteer = volunteerDao.selectOne(eq);
        return volunteer;
    }

    /**
     * 根据志愿者的状态信息分类查询志愿者！
     * @param page
     * @param size
     * @param status
     */
    @Override
    public IPage<Volunteer> getPageVolunteer(Integer page, Integer size, Integer status) {
        IPage<Volunteer> pageInfo = new Page<>(page, size);
        LambdaQueryWrapper<Volunteer> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Volunteer::getStatus,status);
        volunteerDao.selectPage(pageInfo,queryWrapper);
        return pageInfo;
    }
}
